<template>
	<view class="page-container">
		<!-- 反馈列表 -->
		<view class="feedback-list">
			<!-- 卡片列表项 -->
			<uni-card v-for="(item, index) in feedbackList" :key="index" class="feedback-card">
				<view class="card-header">
					<view class="type-date">
						<text class="type">{{ item.type }}</text>
						<text class="date">{{ item.date }}</text>
					</view>
					<uni-badge :type="getStatusType(item.status)" :text="item.status" class="status-badge"></uni-badge>
				</view>
				<view class="card-content">
					<text class="content">{{ item.content }}</text>
				</view>
			</uni-card>
		</view>
	</view>
</template>

<script>
	import { request } from '@/util/request.js';
	export default {
		data() {
			return {
				feedbackList: [
					{
						type: '申请',
						content: '申请新增小区停车位，方便业主停车需求',
						status: '已受理',
						date: '2023-10-15'
					},
					{
						type: '投诉',
						content: '3栋电梯经常故障，希望尽快维修',
						status: '处理中',
						date: '2023-10-12'
					},
					{
						type: '建议',
						content: '建议增加小区绿化面积，提升居住环境',
						status: '已完成',
						date: '2023-10-01'
					},
					{
						type: '申请',
						content: '申请办理门禁卡，新入住业主',
						status: '已驳回',
						date: '2023-09-28'
					}
				]
			};
		},
		methods: {
			// 返回上一页
			navigateBack() {
				uni.navigateBack();
			},
			// 根据状态获取徽章类型
			getStatusType(status) {
				switch(status) {
					case '待审核': return 'primary';
					case '已受理': return 'primary';
					case '处理中': return 'warning';
					case '已完成': return 'success';
					case '已取消': return 'info';
					case '已驳回': return 'error';
					default: return '';
				}
			},
			// 从后端获取反馈列表
			async getFeedbackList() {
				this.feedbackList = [];
				const apply = await request({
					url: 'repair-server/feedback/getApply',
					method: 'GET'
				});
				if (apply.code === 200) {
					this.feedbackList.push(...apply.data);
				}
				const complaint = await request({
					url: 'owner-server/owner/getComplaint',
					method: 'GET'
				});
				if (complaint.code === 200) {
					this.feedbackList.push(...complaint.data);
				}
			}
		},
		// 页面加载时获取反馈列表
		onLoad() {
			this.getFeedbackList();
		}
	};
</script>

<style lang="scss" scoped>
	.page-container {
		padding-bottom: 50px;
	}

	.feedback-list {
		padding: 0 5px;
	}

	.feedback-card {
		margin-bottom: 15px;
		box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
	}

	.card-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 10px;
	}

	.type {
		font-size: 16px;
		font-weight: 500;
		color: #333;
		margin-right: 10px;
	}

	.date {
		font-size: 12px;
		color: #999;
	}

	.status-badge {
		margin-left: 10px;
		font-size: 26px;
	}

	.card-content {
		padding: 10px 0;
	}

	.content {
		font-size: 14px;
		color: #666;
		line-height: 1.5;
	}
</style>
